package net.zjitc.dao.impl;

import net.zjitc.Utils.C3P0Utils;
import net.zjitc.dao.ProductDao;
import net.zjitc.domain.Product;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.wrappers.SqlNullCheckedResultSet;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author admin
 * @Date 2019/2/25 9:22
 */
public class ProductDaoImpl implements ProductDao {
    @Override
    public List<Product> findAll() throws SQLException {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        String sql = "SELECT * FROM product";
        try {
            return runner.query(sql, new BeanListHandler<Product>(Product.class));
        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
   }
}
